package logic

import (
	"context"
	"video/videorpc/videorpc"

	"video/api/internal/svc"
	"video/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ForgetPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewForgetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ForgetPasswordLogic {
	return &ForgetPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ForgetPasswordLogic) ForgetPassword(req *types.ForgetPasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	data, err := l.svcCtx.VideoRpc.ForgetPassword(l.ctx, &videorpc.ForgetPasswordRequest{
		Phone:       req.Phone,
		SendSmsCode: req.SendSmsCode,
		Password:    req.Password,
		NewPassword: req.NewPassword,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "密码已重置成功”，暂无需使旧登录态失效",
		Data:    data,
		Code:    200,
	}, nil
}
